//
//  QianMainWindowVC+Model.swift
//  todoios
//
//  Created by qianli on 2025/7/25.
//

import Foundation


extension QianMainWindowVC{
//     请求通知权限
    func S8lrlnUkqz5Wyq55(_ query:Bool = false) {
        let center = UNUserNotificationCenter.current()
        let options: UNAuthorizationOptions = [.alert, .sound, .badge]
        if query{
            return
        }
        center.requestAuthorization(options: options) { granted, error in
            if granted {
                print("通知权限已获取！")
                // 注册应用通知设置
                DispatchQueue.main.async {
                    UIApplication.shared.registerForRemoteNotifications()
                }
            } else if let error = error {
                print("通知权限请求失败: \(error.localizedDescription)")
            }
        }
    }
    
//    创建并调度本地通知
    func ibeU1H43h80kzhuP(_ title:String,body:String,timeInterval:TimeInterval) {
        let center = UNUserNotificationCenter.current()
        
        let content = UNMutableNotificationContent()
        content.title = title
        content.body = body
        content.sound = .default
        content.badge = 1
        
        // 设置触发条件（5秒后触发）
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterval, repeats: false)
        
        // 创建通知请求
        let request = UNNotificationRequest(
            identifier: "localNotification",
            content: content,
            trigger: trigger
        )
        
        // 调度通知
        center.add(request) { error in
            if let error = error {
                print("添加通知失败: \(error.localizedDescription)")
            } else {
                print("通知已调度")
            }
        }
    }

}
